<script lang="ts" setup>
import { useGlobSetting } from "@/hooks/setting";
import AppUser from "./app-user.vue";
import AppMenu from "./app-menu.vue";
import Timer from "@/services/timer?worker";
import { onMounted, ref } from "vue";
import dayjs from "dayjs";

const { title } = useGlobSetting();
const time = ref<string>();

function counter() {
  const timer = new Timer();
  timer.onmessage = (ev) => {
    time.value = dayjs(ev.data * 1000).format("YYYY/MM/DD HH:mm:ss");
  };
  timer.postMessage(Date.now() / 1000);
}

onMounted(() => {
  counter();
});
</script>

<template>
  <div class="def-layout">
    <div class="def-head bg-sky-600">
      <div class="title-panel">
        <span>{{ title }}</span>
      </div>
      <div class="time-panel">{{ time }}</div>
      <div class="state-panel">
        <app-user />
      </div>
    </div>
    <div class="def-body">
      <div class="menu-panel">
        <app-menu />
      </div>
      <div class="main-panel">
        <RouterView></RouterView>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.def-layout {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;

  .def-head {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    height: 80px;
    min-height: 80px;

    .title-panel {
      padding-left: 20px;
      color: white;
      font-size: xx-large;
      // background-color: aquamarine;
    }

    .time-panel {
      color: white;
    }

    .state-panel {
      padding-right: 20px;
      // background-color: burlywood;
    }
  }

  .def-body {
    display: flex;
    flex: auto;
    flex-direction: row;
    overflow: hidden;

    .menu-panel {
      width: 250px;
      height: 100%;
      min-height: 100%;
      overflow-x: hidden;
      overflow-y: auto;
    }

    .main-panel {
      position: relative;
      flex: auto;
      height: 100%;
      min-height: 100%;
      overflow-x: hidden;
      overflow-y: auto;
    }
  }
}
</style>
